//
//  HYInternetHeaderView.m
//  XPlayer
//
//  Created by liguoqing on 2023/9/11.
//

#import "HYInternetHeaderView.h"

@interface HYInternetHeaderView ()

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIButton *deleBtn;

@property (nonatomic, copy) dispatch_block_t clearBlock;

@end

@implementation HYInternetHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if(self){
        self.contentView.backgroundColor = AppBgThemeColor;
        [self.contentView addSubview:self.titleLabel];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.centerY.equalTo(self.contentView);
        }];
        [self.contentView addSubview:self.deleBtn];
        [self.deleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-15);
            make.top.bottom.equalTo(self);
            make.width.mas_equalTo(44);
        }];
    }
    return self;
}

- (void)setHeaderTitle:(NSString *)headerTitle
{
    _headerTitle = headerTitle;
    self.titleLabel.text = headerTitle;
}

- (void)deleBtnAction
{
    if(self.clearBlock){
        self.clearBlock();
    }
}

- (void)clearPreviewHistoryRecordBlok:(dispatch_block_t)clearBlock
{
    self.clearBlock = clearBlock;
}

- (void)setIsHiddenDelete:(BOOL)isHiddenDelete
{
    _isHiddenDelete = isHiddenDelete;
    self.deleBtn.hidden = isHiddenDelete;
}

- (UILabel *)titleLabel
{
    if(!_titleLabel){
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textColor = UIColor.systemGrayColor;
        _titleLabel.font = FONT_BOLD_SIZE(14);
    }
    return _titleLabel;
}

- (UIButton *)deleBtn
{
    if(!_deleBtn){
        _deleBtn = [[UIButton alloc]init];
        _deleBtn.hidden = YES;
        [_deleBtn setImage:[UIImage imageNamed:@"icon_clear"] forState:UIControlStateNormal];
        [_deleBtn addTarget:self action:@selector(deleBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleBtn;
}

@end
